#include "fig_exploding_collection.h"
#include "fig_exploding.h"
#include "fig_exploding_gemini.h"

FIGExplodingCollection::FIGExplodingCollection(FIGExploding::EXPLODING_TYPES Type) : m_Type(Type)
{

}

FIGExplodingCollection::~FIGExplodingCollection()
{

}

void		FIGExplodingCollection::Render(const math::Vec2& Offset,float Scale)
{
	for(unsigned int i = 0; i < m_Explodings.size(); i++)
	{
		FIGExploding*  pExploding = m_Explodings[i];
		pExploding->Render(Offset,Scale);
	}
}


void		FIGExplodingCollection::RenderDebug(const math::Vec2& Offset,float Scale)
{
	for(unsigned int i = 0; i < m_Explodings.size(); i++)
	{
		FIGExploding*  pExploding = m_Explodings[i];
		pExploding->RenderDebug(Offset,Scale);
	}
}


void		FIGExplodingCollection::Tick(float dt)
{
	for(unsigned int i = 0; i < m_Explodings.size(); i++)
	{
		FIGExploding*  pExploding = m_Explodings[i];
		pExploding->Tick(dt);
	}
}


void		FIGExplodingCollection::Clear()
{
	for(unsigned int i = 0; i < m_Explodings.size(); i++)
	{
		FIGExploding*  pExploding = m_Explodings[i];
		pExploding->Clear();
	}

	
	for( int i = (int)m_Explodings.size() - 1; i >= 0; i--)
	{
		FIGExploding*  pExploding = m_Explodings[i];
		UTIL_SAFE_DELETE(pExploding);
	}
	m_Explodings.resize(0);
}
	

void		FIGExplodingCollection::Spawn(	const math::Vec2& Pos, 											
											float SizeScale,
											float Rotation,
											float Delay
										  )
{
	for( int i = 0; i < (int)m_Explodings.size(); i++)
	{
		FIGExploding*  pExploding = m_Explodings[i];
		if(!pExploding->IsAlive())
		{
			pExploding->ReSpawn(Pos,SizeScale,Rotation,Delay);
			return;
		}
	}

	
	
	if( m_Type != FIGExploding::EXPLODING_GEMINI)
	{
		FIGExploding*  pExploding = NULL;
		pExploding = new FIGExploding(m_Type);
		m_Explodings.push_back(pExploding);
		pExploding->ReSpawn(Pos,SizeScale,Rotation,Delay);
	}
	else
	{
		FIGExplodingGemini* pExploding = NULL;
		pExploding = new FIGExplodingGemini(m_Type);
		m_Explodings.push_back(pExploding);
		pExploding->ReSpawn(Pos,SizeScale,Rotation,Delay);
	}	
	
	
	
}

	